Skip to content

Expand ~/$HOME in push input paths - #141

Merged
grimicorn merged 1 commit into
mainfrom
agent/expand-tilde-push
Aug 27, 2026
Merged

Expand ~/$HOME in push input paths#141
grimicorn merged 1 commit into
mainfrom
agent/expand-tilde-push

Conversation

@grimicorn-agent

Copy link
Copy Markdown
Collaborator

What & why

markpost push '~/vault/**' never matched anything: the user quotes the glob to stop the shell expanding it early, but that also stops the shell expanding the leading ~, so a literal ~ was globbed against the filesystem and matched nothing (the path silently landed in missing).

This expands a leading home reference (~, $HOME, or ${HOME}) in resolveMarkdownInputs (src/libs/files.ts) before resolving each input, so quoted and unquoted inputs resolve to the same target.

Decisions

  • No existing expander to reuse. The issue suggested reusing "the outputDirectory expansion," but the codebase does no tilde/$HOME expansion anywhere today (getOutputDirectory in markdown.ts reads the value verbatim). So this adds a small, self-contained expandHomeDirectory helper rather than duplicating anything.
  • Expansion is leading-only. Only a reference that is the whole argument (~) or a <ref>/… prefix is expanded. ~backup/note.md and $HOMEBREW/note.md are left literal — they are not home references.
  • String splice, not path.join. The remainder (including glob metacharacters like **) is spliced onto the home path directly so join's normalization can't alter the glob pattern.
  • missing keeps the raw input. An unmatched ~/nope.md is reported as the user typed it, consistent with this file's "read the way the user typed them" convention; files/skipped carry the resolved paths. Locked in by a test.
  • Supported forms: ~, ~/…, $HOME, $HOME/…, ${HOME}, ${HOME}/….

Tests

Added a home directory expansion block in tests/libs/files.test.ts covering: ~/…, $HOME/…, ${HOME}/… globs matching under home; bare ~ and $HOME resolving to the home directory; non-references (~backup, $HOMEBREW) left untouched; and an unmatched home reference reported raw. All 715 tests pass; lint and typecheck clean.

Viewable

CLI behavior — run markpost push '~/vault/**' against a vault under $HOME.

Closes #134

Follow-up suggestions

  • Escape glob metacharacters in the expanded home path — a home directory containing a glob metacharacter ([, *, ?, etc.) makes an expanded ~/… glob silently match nothing; escape the home-path segment on the glob branch (threading base/remainder through resolveInput) so such home paths still resolve. (suggested: P4, effort: S, evidence: src/libs/files.ts expandHomeReference/collectFromGlob)

markpost push '~/vault/**' quoted the glob to stop the shell touching
it, which also stopped the shell expanding the leading ~, so the literal
~ globbed against nothing. Expand a leading ~, $HOME, or ${HOME} in
resolveMarkdownInputs before resolving, so quoted and unquoted inputs
resolve the same target. The unmatched-input report keeps the raw path
the user typed.

Closes #134
@grimicorn-agent grimicorn-agent added the has-suggestions PR carries follow-up suggestions for the improvement digest label Aug 27, 2026
@grimicorn-agent

Copy link
Copy Markdown
Collaborator Author

Independent code review trail

Ran the independent reviewer (Opus) on the branch diff over 2 rounds.

Round 1 — 4 findings

  • Fixed — join mangles glob patterns: switched expandHomeReference from path.join to a direct string splice (${homedir()}${input.slice(prefix.length)}) so glob metacharacters and separators in the remainder survive untouched.
  • Fixed — ${HOME} brace form not expanded: added ${HOME} to HOME_REFERENCE_PREFIXES (the loop and helper handle it with no other change).
  • Fixed — untested $HOME branches: added tests for bare $HOME and a non-reference $HOMEBREW/note.md.
  • Skipped — test stubs process.env.HOME while code reads os.homedir(): on POSIX homedir() prefers $HOME, and this suite is already POSIX-only (it relies on symlinks, /dev/null, and chmod 0o000, all of which fail on Windows). The HOME stub matches the suite's established platform assumption.

Round 2 — 6 findings

  • Fixed — lock in that missing reports the raw input, not the expanded path: added a test asserting an unmatched ~/nope.md is reported verbatim.
  • Dismissed (empirically) — trailing separator produces a doubled slash: verified globSync('…//vault/**') matches identically to the single-slash form, so no fix needed.
  • Deferred (follow-up suggestion in PR body) — glob metacharacters in the home path itself: a real but very rare edge (a home directory containing [, *, etc.); the correct fix requires threading an escaped/unescaped base+remainder through resolveInput, disproportionate for this P3. Recorded as a P4 follow-up.
  • Skipped — Windows \ separators / vi.mock('node:os'): POSIX-only tool (see round 1 rationale); no change.
  • Skipped — file literally named ~/$HOME: legal but vanishingly rare, and the shell would expand the unquoted form anyway; not worth a second existsSync per input.

Reviewer confirmed no Code-Standards violations (small functions, flat control flow with guard clauses, full names, no rule-of-three breach).

Final: lint clean, typecheck clean, 715 tests passing.

@grimicorn
grimicorn merged commit f37c04a into main Aug 27, 2026
3 checks passed
@grimicorn
grimicorn deleted the agent/expand-tilde-push branch August 27, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

has-suggestions PR carries follow-up suggestions for the improvement digest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expand ~/$HOME in push input paths

2 participants